using System;
using System.Linq;

namespace ECatalog.Models.Structures
{
    public class StructureRepository : IStructureRepository
    {
        public Structure Add(Structure structure)
        {
            using (var db = new DbContainer())
            {
                try
                {
                    db.Structures.Add(structure);
                    db.SaveChanges();
                }
                catch (Exception)
                {

                }
                return structure;
            }
        }

        public void Remove(int structureid)
        {
            using (var db = new DbContainer())
            {
                var s = db.Structures.SingleOrDefault(st => st.StructureId == structureid);
                if (s != null)
                {
                    try
                    {
                        db.Structures.Remove(s);
                        db.SaveChanges();
                    }
                    catch (Exception)
                    {

                    }
                }
            }
        }
    }
}